GENPRINT - Generalized Printer for VB by Guinn Unger Unger Business Systems 11926 Barrett Brae Houston, TX 77072-4004 Phone: (713) 498-8517 Fax: (713) 498-8518 Compuserve: Guinn Unger, 71053,2332 NOTE: The GENPRINT setup routine was failing with a PostScript printer. It turns out that the dmout.dmDriverExtra must be set to 0 for PS printers to initialize. This change is hard-coded in the routine now. (Note: There is the potential that this could cause problems with printer drivers which use the private data area. This has not been explored any further at this time.) The GENPRINT forms and routines are designed to give the VB programmer additional flexibility over using the VB PRINTER object. The primary advantages are: 1. The ability to abort the print job. This is a significant shortcoming of the VB PRINTER object in some situations. 2. The ability to select/change printers without changing the Windows default printer. This includes changing the printer orientation. 3. The ability to have more than one printer active. GENPRINT consists of the following: 1. A form (GPRINTER.FRM) which acts as a dummy form and contains the CBK.VBX custom control. This form is not actually necessary if the appropriate controls are present on another form. 2. A form (ABORTFOR.FRM) which is displayed while printing is in progress. It contains a command button which is pressed to abort the print job. 3. A form (PRTSETUP.FRM) which mimics the dialog box used in Microsoft Word. 4. A module (GPRINTER.BAS) which contains the various subs and functions which are called by the user. 5. A custom callback control (CBK.VBX) which is necessary for the abort function to work properly. This custom control was supplied as part of Appleman's book and may be distributed freely. General Procedure for using GENPRINT 1. The functions are called as follows: prhdc = GenPrinterSetup(ThisPrinter) where prhdc is an integer which now contains the device context for ThisPrinter. ThisPrinter is a string of the form "HP LaserJet IIP,HPPCL,LPT1:" as stored in the WIN.INI file. Note that prhdc is passed to virtually all of the other GENPRINT routines. This routine as written call DefaultFontSetup and uses "Ariel" font in 10 pt size. SetupDocInfo ("PROGNAME") This supplies the information used by Print Manager. SetAbortCallback (prhdc) This sets up the abort procedure. ShowAbortForm (False) 'must not be system modal This displays the abort form. di = StartDocument(prhdc) This tells Print Manager that we are starting a document. di = StartAPage(prhdc) Start a page! PrintText prhdc, AString {There are numerous other functions which can now be called to draw lines, rectangles, etc. The font can also be changed. See the GPRINTER.BAS module for available functions.} di = EndAPage(prhdc) This is called each time you want to end a page. If more pages are to be printed, be sure to call StartAPage again. di = EndDocument(prhdc) This tells Print Manager that the document is finished. UnloadAbortForm Get rid of the abort form. GenPrinterClose prhdc Clean up after printer. After this call prhdc is no longer valid. MISCELLANEOUS ROUTINES The ClipString and SplitLines routines were developed to allow the user to clip or split a text string which might be too long to fit in a given space. The maximum length passed to each routine is in inches. ClipString simply trims the string to the maximum number of characters which will fit in the given length. Split lines parses the string into 3 separate strings and throws away any extra. (The number of strings could be increased easily.) Both routines take into account the current font size and other characteristics. OTHER INFORMATION Several routines are included which show information about the DevMode structure, printers, fonts, etc. Feel free to experiment with these as you are using the routines. These routines have primarily been tested with laser printers (300 dpi). If you use them with other printers, be sure to test them carefully. The routines seem to work fine with local and network printers. If would be relatively easy to add additional functions to the routines. See Appleman's book for more information.